package com.paomi.client.activity.classify.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.paomi.client.R;
import com.paomi.client.activity.classify.model.SearchGetBeaan;
import com.paomi.client.activity.newsDetail.model.NewsListJson;
import com.paomi.client.activity.onlineSeat.model.SeatBean;
import com.paomi.client.fragment.first.model.TicketJson;
import com.paomi.client.utils.UIUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by pc on 2018/3/13.
 * 搜索的列表适配
 */

public class ClassifyListAdapter extends RecyclerView.Adapter<ClassifyListAdapter.ViewHolder> {
    Context context;
    List<SearchGetBeaan> mlist = new ArrayList<>();
    List seatBeans = null;//在线选座座位信息
    OnItemClick onClickListener;
    private Typeface mType;
    private List<TicketJson> ticketJsonList=new ArrayList<>();//演出信息
    private List<NewsListJson> listJsons=new ArrayList<>();//资讯数据信息

    public void OnItemClick(OnItemClick onClickListener) {
        this.onClickListener = onClickListener;
    }


    public ClassifyListAdapter(Context context, Typeface typeface) {
        this.context = context;
        this.mType = typeface;
    }

    public void setData(List<SearchGetBeaan> list, List<TicketJson> ticketJsons,List<NewsListJson> listJsons) {
        this.mlist = list;
        this.ticketJsonList = ticketJsons;
        this.listJsons = listJsons;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.search_classify_item, parent, false));
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        SearchGetBeaan ticket = mlist.get(position);
        holder.searchIv.setTypeface(mType);
        holder.searchTv.setText(ticket.getName());
        holder.recyclerClassify.setLayoutManager(UIUtils.getRecyclerViewManager(false,(Activity) context));
        if(ticket.getName().equals("资讯")){//资讯
            holder.bg_lay.setBackgroundResource(R.mipmap.img_search_category_information);
            holder.searchIv.setText(context.getResources().getString(R.string.list_mess));
            InfoListAdapter infoListAdapter=new InfoListAdapter(context);
            holder.recyclerClassify.setAdapter(infoListAdapter);
            infoListAdapter.setData(listJsons);
        }else if(ticket.getName().equals("演出")){//演出
            holder.bg_lay.setBackgroundResource(R.mipmap.img_search_category_performance);
            holder.searchIv.setText(context.getResources().getString(R.string.list_show));
            ShopListAdapter shopListAdapter=new ShopListAdapter(context);
            holder.recyclerClassify.setAdapter(shopListAdapter);
            shopListAdapter.setData(ticketJsonList);
        }
    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.search_iv)
        TextView searchIv;
        @BindView(R.id.search_tv)
        TextView searchTv;
        @BindView(R.id.bg_lay)
        LinearLayout bg_lay;
        @BindView(R.id.recycler_classify)
        RecyclerView recyclerClassify;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnItemClick {
//        void setOnItemClick(View view, int pos);
    }
}
